﻿using System;
using System.Linq.Expressions;

namespace Hvam.SharePoint.Search.Language
{
    public static class KeywordQueryExpression
    {
        public static Expression Contains(ConstantExpression left, ConstantExpression right)
        {
            if (!(left.Value is KeywordQueryProperty) || !(right.Value is string))
            {
                throw new ArgumentException();
            }

            var method = typeof(KeywordQueryProperty).GetMethod("Contains", new[] { typeof(string) });

            return Expression.Call(left, method, right);
        }

        public static ConstantExpression Property(string name)
        {
            return Expression.Constant(new KeywordQueryProperty(name));
        }
    }
}
